from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
from  pyecharts import options as opts
import json

virus_map = Map()

f = open("O:\学Python\资料\第1-12章资料\第1-12章资料\资料\可视化案例数据\地图数据\疫情.txt","r",encoding="UTF-8")
data = json.loads(f.read())
data_dict = data["areaTree"][0]["children"]
data_list = []
for province_data in data_dict:
    province_name = province_data["name"]
    province_value = province_data["total"]["confirm"]
    data_list.append((province_name,province_value))
print(data_list)
virus_map = virus_map.add("疫情地图",data_list,"china")
# set_global_opts() 设置全局配置选项
# visualmap_opts = opts.VisualMapOpts():视觉映射配置选项
virus_map.set_global_opts(visualmap_opts=opts.VisualMapOpts())
virus_map.render()
f.close()
# map = Map()
# data  = [
#     ("北京",99),
#     ("上海",199),
#     ("广州",299),
#     ("深圳",399)
# ]
# map.add("地图",data,"china")
# map.set_global_opts(
#     visualmap_opts=VisualMapOpts(
#         is_show=True,
#         is_piecewise=True,
#         pieces=[]
#     )
# )